package com.future.cor.v2;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 *
 * @author weiruibai.vendor
 * Date: 2022/2/21 18:15
 */
public class MyFilterChain {

    int curIndex;

    List<MyFilter> filters;

    public MyFilterChain() {
        filters = new ArrayList<>();
        curIndex = 0;
    }

    public MyFilterChain add(MyFilter myFilter) {
        filters.add(myFilter);
        return this;
    }

    public void doFilter(Request request, Response response) {
        if (curIndex == filters.size()) {
            return;
        }
        MyFilter myFilter = filters.get(curIndex++);
        System.out.println("before");
        myFilter.doFilter(request, response, this );
        System.out.println("after");

    }
}
